/*
package com.thwj.common.utils;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.thwj.common.constant.Constants;
import com.thwj.common.utils.http.HttpUtils;
import com.thwj.framework.redis.RedisCache;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

*/
/**
 * <b>功能名：</b>WxUtils<br>
 * <b>说明：</b><br>
 * <b>著作权：</b> Copyright (C) 2019   CORPORATION<br>
 * <b>修改履历：
 *
 * @author 2020-07-13 hufeng
 *//*

@Component
public class WxUtils {
    @Autowired
    private WxProperties wxConfig;

    @Autowired
    RedisCache redisCache;

    private static WxProperties wxConfigs;

    private static RedisCache redisCaches;

    private static final Logger log = LoggerFactory.getLogger(WxUtils.class);

    private static final String ERRCODE = "errcode";

    private static final String ERRMSG = "errmsg";


    */
/**
     * 初始化获取配置
     *//*

    @PostConstruct
    public void init() {
        wxConfigs = this.wxConfig;
        redisCaches = this.redisCache;
    }

    */
/**
     * <b>方法名：</b>返回微信用户的获取小程序openid openid<br>
     * <b>说明：</b> <br>
     *
     * @param code
     * @return java.lang.String
     * <b>修改履历：</b>
     * @author 2020/7/13   hufeng
     *//*

    public static String getMiniOpenId(String code) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOnce("appid", wxConfigs.getMiniAppId());
        jsonObject.putOnce("secret", wxConfigs.getMiniSecret());
        jsonObject.putOnce("js_code", code);
        jsonObject.putOnce("grant_type", wxConfigs.getGrantType().get(0));
        String value = HttpUtils.sendGet(wxConfigs.getCode2SessionUrl(), jsonObject);
        if (JSONUtil.isJsonObj(value)) {
            JSONObject returnJson = new JSONObject(value);
            if (returnJson.containsKey(ERRCODE)) {
                log.error("微信获取OpenId错误：{},{}", returnJson.getInt(ERRCODE), returnJson.getStr(ERRMSG));
                return "";
            } else {
                return value;
            }
        } else {
            log.error("微信获取OpenId错误：{}", value);
            return "";
        }

    }


    */
/**
     * <b>方法名：</b>返回微信用户的获取公众号openid<br>
     * <b>说明：</b> <br>
     *
     * @param code
     * @return java.lang.String
     * <b>修改履历：</b>
     * @author 2020/7/13   hufeng
     *//*

    public static String getGzhOpenId(String code) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOnce("appid", wxConfigs.getGzhAppid());
        jsonObject.putOnce("secret", wxConfigs.getGzhSecret());
        jsonObject.putOnce("code", code);
        log.info("code:{}", code);
        jsonObject.putOnce("grant_type", wxConfigs.getGrantType().get(0));
        String value = HttpUtils.sendGet(wxConfigs.getCode2AccessTokenUrl(), jsonObject);
        if (JSONUtil.isJsonObj(value)) {
            JSONObject returnJson = new JSONObject(value);
            if (returnJson.containsKey(ERRCODE)) {
                log.error("微信获取OpenId错误：{},{}", returnJson.getInt(ERRCODE), returnJson.getStr(ERRMSG));
                return "";
            } else {
                return value;
            }
        } else {
            log.error("微信获取OpenId错误：{}", value);
            return "";
        }

    }

    */
/**
     * <b>方法名：</b>获取公众号的用户信息<br>
     * <b>说明：</b> <br>
     *
     * @param
     * @return java.lang.String
     * <b>修改履历：</b>
     * @author 2020/7/13   hufeng
     *//*

    public static String getGzhUserInfo(String accessToken, String openid) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOnce("access_token", accessToken);
        jsonObject.putOnce("openid", openid);
        jsonObject.putOnce("lang", "zh_CN");
        String value = HttpUtils.sendGet(wxConfigs.getGetUserInfoUrl(), jsonObject);
        if (JSONUtil.isJsonObj(value)) {
            JSONObject returnJson = new JSONObject(value);
            if (returnJson.containsKey(ERRCODE)) {
                log.error("微信获取用户信息失败：{},{}", returnJson.getInt(ERRCODE), returnJson.getStr(ERRMSG));
                return "";
            } else {
                return value;
            }
        } else {
            log.error("微信获取用户信息失败：{}", value);
            return "";
        }


    }

    */
/**
     * 获取微信分享参数
     *//*

    public static String getShareToken() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOnce("appid", wxConfigs.getGzhAppid());
        jsonObject.putOnce("secret", wxConfigs.getGzhSecret());
        jsonObject.putOnce("grant_type", wxConfigs.getGrantType().get(1));
        String value = HttpUtils.sendGet("https://api.weixin.qq.com/cgi-bin/token", jsonObject);
        String accessToken = "";
        if (JSONUtil.isJsonObj(value)) {
            JSONObject returnJson = new JSONObject(value);
            if (returnJson.containsKey(ERRCODE)) {
                log.error("微信获取ACCESS_TOKE失败：{},{}", returnJson.getInt(ERRCODE), returnJson.getStr(ERRMSG));
                return "";
            } else {
                accessToken = (String) returnJson.get("access_token");
                return accessToken;
            }
        } else {
            log.error("微信获取ACCESS_TOKE失败：{}", value);
            return "";
        }
    }

    */
/**
     * 获取分享ticket
     *//*

    public static String getShareTicket() {
        String accessToken = getShareToken();
        JSONObject ticketObject = new JSONObject();
        ticketObject.putOnce("access_token", accessToken);
        ticketObject.putOnce("type", "jsapi");
        String ticketvalue = HttpUtils.sendGet("https://api.weixin.qq.com/cgi-bin/ticket/getticket", ticketObject);
        if (JSONUtil.isJsonObj(ticketvalue)) {
            JSONObject ticketJson = new JSONObject(ticketvalue);
            if (ticketJson.containsKey("ticket")) {
                return (String) ticketJson.get("ticket");
            } else {
                log.error("微信获取ticket失败：{},{}", ticketJson.getInt(ERRCODE), ticketJson.getStr(ERRMSG));
                return "";
            }
        } else {
            log.error("微信获取ticket失败：{}", ticketvalue);
            return "";
        }
    }


    */
/**
     * @param data 待签名数据
     * @param url  url
     * @return 签名
     *//*

    public static String generateShareSignature(final Map<String, String> data, String url) {
        Set<String> keySet = data.keySet();
        String[] keyArray = keySet.toArray(new String[keySet.size()]);
        Arrays.sort(keyArray);
        StringBuilder sb = new StringBuilder();
        for (String k : keyArray) {
            if (k.equals("sign")) {
                continue;
            }
            if (data.get(k).trim().length() > 0) // 参数值为空，则不参与签名
                sb.append(k).append("=").append(data.get(k).trim()).append("&");
        }
        sb.append("url=").append(url);
        try {
            return sha1(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

    */
/**
     * sha1签名
     *//*

    public static String sha1(String data) throws Exception {
        String sha1 = DigestUtils.sha1Hex(data.getBytes("UTF-8"));
        return sha1;
    }

    */
/**
     * <b>方法名：</b> 微信获取token<br>
     * <b>说明：</b> <br>
     *
     * @param
     * @return java.lang.String
     * <b>修改履历：</b>
     * @author 2020/7/21 10:13  hufeng
     *//*

    public static String getToken() {
        if (redisCaches.hasKey(Constants.WX_ACCESS_TOKEN)) {
            return redisCaches.getCacheObject(Constants.WX_ACCESS_TOKEN);
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.putOnce("appid", wxConfigs.getMiniAppId());
        jsonObject.putOnce("secret", wxConfigs.getMiniSecret());
        jsonObject.putOnce("grant_type", wxConfigs.getGrantType().get(1));
        String vaule = HttpUtils.sendGet(wxConfigs.getAccessToken(), jsonObject);
        JSONObject returnJson = new JSONObject(vaule);
        if (returnJson.containsKey(ERRCODE)) {
            log.error("微信获取Token错误：{},{}", returnJson.getInt(ERRCODE), returnJson.getStr(ERRMSG));
            return "";
        } else {
            redisCaches.setCacheObject(Constants.WX_ACCESS_TOKEN, vaule, 7000, TimeUnit.SECONDS);
            return vaule;
        }

    }

    public static String getAccessToken() {
        String response = getToken();
        log.debug("response:" + response);
        JSONObject jsonObject = JSONUtil.parseObj(response);
        return jsonObject.getStr("access_token", "");
    }


    */
/**
     * 解密微信手机号
     *//*


    public static String getPhoneNumber(String code) {
        JSONObject json = new JSONObject();
        json.put("code", code);

        // 请求url
        String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + getAccessToken();
        // 发起请求
        String response = HttpUtils.sendPost(url, com.alibaba.fastjson.JSONObject.toJSONString(json));
        return response;

    }

    */
/**
     * 下单成功推送模板
     * 推送微信消息
     * 40003	touser字段openid为空或者不正确
     * 40037	订阅模板id为空不正确
     * 43101	用户拒绝接受消息，如果用户之前曾经订阅过，则表示用户取消了订阅关系
     * 47003	模板参数不准确，可能为空或者不满足规则，errmsg会提示具体是哪个字段出错
     * 41030	page路径不正确，需要保证在现网版本小程序中存在，与app.json保持一致
     *//*

    public static Object sendWXMsg(Map map, String goodsName, String openId, String time) throws ParseException {

        JSONObject json = new JSONObject();
        JSONObject jsonData = new JSONObject();
        json.put("touser", openId);
        json.put("template_id", "BAyKHZQSJNNUmCtTYgjSnLMuvFS1NjVw9ezwJniBvLk");

        String merOrderId = (String) map.get("merOrderId");
        String payTime = (String) map.get("payTime");

        String totalAmount = (String) map.get("totalAmount");
        String s = BigDecimal.valueOf(Long.valueOf(totalAmount)).divide(new BigDecimal(100)).toString();

        jsonData.put("character_string1", initJson(merOrderId)); // 订单编号
        jsonData.put("date2", initJson(payTime)); // 支付时间
        jsonData.put("thing3", initJson(goodsName)); // 商品名称
        jsonData.put("amount4", initJson(s)); // 支付金额
        jsonData.put("thing6", initJson("您的校服将于" + time + "送至你所填写的地址")); // 温馨提示

        json.put("data", jsonData);

        // 请求url
        String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + getAccessToken();
        // 发起请求
        String response = HttpUtils.sendPost(url, com.alibaba.fastjson.JSONObject.toJSONString(json));
        System.out.println("参数：：：：" + response);
        return response;
    }

    */
/**
     * 下单成功推送模板 取货码方式
     * 推送微信消息
     * 40003	touser字段openid为空或者不正确
     * 40037	订阅模板id为空不正确
     * 43101	用户拒绝接受消息，如果用户之前曾经订阅过，则表示用户取消了订阅关系
     * 47003	模板参数不准确，可能为空或者不满足规则，errmsg会提示具体是哪个字段出错
     * 41030	page路径不正确，需要保证在现网版本小程序中存在，与app.json保持一致
     *//*

    public static Object sendWXMsgForQR(Map map, String goodsName, String openId, String time, String address) throws ParseException {

        JSONObject json = new JSONObject();
        JSONObject jsonData = new JSONObject();
        json.put("touser", openId);
        json.put("template_id", "BAyKHZQSJNNUmCtTYgjSnLMuvFS1NjVw9ezwJniBvLk");

        String merOrderId = (String) map.get("merOrderId");
        String payTime = (String) map.get("payTime");

        String totalAmount = (String) map.get("totalAmount");
        String s = BigDecimal.valueOf(Long.valueOf(totalAmount)).divide(new BigDecimal(100)).toString();

        jsonData.put("character_string1", initJson(merOrderId)); // 订单编号
        jsonData.put("date2", initJson(payTime)); // 支付时间
        jsonData.put("thing3", initJson(goodsName)); // 商品名称
        jsonData.put("amount4", initJson(s)); // 支付金额
        jsonData.put("thing6", initJson("您的校服将于" + time + "送至" + address)); // 温馨提示

        json.put("data", jsonData);

        // 请求url
        String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + getAccessToken();
        // 发起请求
        String response = HttpUtils.sendPost(url, com.alibaba.fastjson.JSONObject.toJSONString(json));
        System.out.println("参数：：：：" + response);
        return response;
    }

    */
/**
     * 初始化json数据
     *
     * @param info
     * @return
     *//*

    private static JSONObject initJson(String info) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("value", info);
        return jsonObject;
    }
}
*/
